﻿package mortal.game.view.levelReward
{
    import Message.Game.*;
    import flash.events.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.proxy.*;
    import mortal.mvc.core.*;
    import mortal.mvc.interfaces.*;

    public class LevelRewardController extends Controller
    {
        private var levelRewardProxy:LevelRewardProxy;
        private var _levelRewardModule:LevelRewardModule;

        public function LevelRewardController()
        {
            this.levelRewardProxy = GameProxy.levelReward;
            return;
        }// end function

        override protected function initServer() : void
        {
            return;
        }// end function

        private function onWinShow(event:DataEvent) : void
        {
            LevelRewardModule.allowShow = true;
            if (view.isHide)
            {
                view.show();
            }
            return;
        }// end function

        override protected function initView() : IView
        {
            if (LevelRewardModule.allowShow == false)
            {
                return null;
            }
            if (this._levelRewardModule == null)
            {
                this._levelRewardModule = new LevelRewardModule();
            }
            return this._levelRewardModule as IView;
        }// end function

        private function ReceiveLevelRewardGifts(event:DataEvent) : void
        {
            var _loc_2:* = event.data as int;
            this.levelRewardProxy.getLevelReward(_loc_2);
            return;
        }// end function

        private function get levelRewardModule() : LevelRewardModule
        {
            if (this.view == null)
            {
                throw new Error("需要先判断this.view是否为null,方可使用");
            }
            return LevelRewardModule(this.view);
        }// end function

        private function loadGiftInfoAndUpdateWin(param1:SLevelGiftInfo) : void
        {
            Cache.instance.levelReward.hasGotLevelGiftInfo = param1;
            if (this.view)
            {
                this.levelRewardModule.refresh();
            }
            this.refreshLevelRewardIcon();
            return;
        }// end function

        private function roleUpdateAndRefreshWin(event:Event = null) : void
        {
            if (this.view)
            {
                this.levelRewardModule.refresh();
            }
            this.refreshLevelRewardIcon();
            return;
        }// end function

        private function refreshLevelRewardIcon() : void
        {
            var _loc_1:* = Cache.instance.levelReward.canReceiveGiftsNum;
            if (_loc_1 > 0)
            {
                WelfareIcon.instance.playEffect();
                WelfareIcon.instance.numText.text = _loc_1 + "";
                WelfareIcon.instance.numText.visible = true;
            }
            else
            {
                WelfareIcon.instance.numText.visible = false;
                WelfareIcon.instance.stopEffect();
            }
            return;
        }// end function

    }
}
